/* eslint-disable no-restricted-globals */
import { routerList } from './RouteBeforeConfig'
import RouteConfig from './index'
import { Alert } from 'antd'

function RouteBefore() {
  
  const currentPath = routerList.filter((item) => item.path === location.pathname)[0]
  function closeHandle() {
    location.pathname = '/'
  }

  if (currentPath) {
    if (currentPath.needLogin && !localStorage.getItem('userToken')) {
      return (
        <Alert
          message="请先登录"
          type="warning"
          closable
          onClose={closeHandle}
          style={{
            marginTop: '30px',
            marginBottom: '30px',
          }}
        />
      )
    }
  }
  return <RouteConfig />
}
export default RouteBefore
